import { RankBaseItem } from "./RankBaseItem";
import { GTextFormat } from "../../../common/GTextFormat";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { TToplist } from "../../../../Message/Db/Tables/TToplist";
import { ItemData } from "../../resource/info/ItemData";
import { ColorConfig } from "../../resource/ColorConfig";
import { CareerUtil } from "../common/util/CareerUtil";
import { CareerConfig } from "../../resource/CareerConfig";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { JSON } from "../../../../com/mui/serialization/json/JSON";
import { Tooltip } from "../common/tooltip/Tooltip";
import { LayerManager } from "../../manager/LayerManager";
import { Global } from "../../../../com/gengine/global/Global";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class EquipmentRankItem
    
    export  class EquipmentRankItem extends RankBaseItem
    {
        constructor()
        {
            super();
            this.init();
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            return;
        }

        public get isClick(): Boolean
        {
            return this._isClick;
        }

        public set isClick(arg1: Boolean)
        {
            this._isClick = arg1;
            return;
        }

        protected init(): void
        {
            this._tf = new GTextFormat("", 12, 11661311, false, false, false, null, null, flash.text.TextFormatAlign.CENTER);
            this._rankTxt = this.createTextField("", 0, 0, 25, 33, this._tf);
            this._nameTxt = this.createTextField("", 27, 0, 160, 33, this._tf);
            this._careerTxt = this.createTextField("", 160, 0, 80, 33, this._tf);
            this._ownerTxt = this.createTextField("", 240, 0, 90, 33, this._tf);
            this._scoreTxt = this.createTextField("", 320, 0, 70, 33, this._tf);
            this._rangeTxt = this.createTextField("", 375, 0, 120, 33, this._tf);
            this._bitmap = new Object /* flash.display.Bitmap */();
            var loc1=ObjCreate.createBg(0, 25, 460, 2, this, ImagesConst.SplitLine);
            return;
        }

        protected createTextField(arg1: string, arg2: int, arg3: int, arg4: int, arg5: int, arg6: Object /* flash.text.TextFormat */): Object /* flash.text.TextField */
        {
            var loc1=null;
            (loc1 = new Object /* flash.text.TextField */()).x = arg2;
            loc1.y = arg3;
            loc1.width = arg4;
            loc1.height = arg5;
            loc1.selectable = false;
            loc1.defaultTextFormat = arg6;
            loc1.text = arg1;
            addChild(loc1);
            return loc1;
        }

        public updateItem(arg1: TToplist): void
        {
            var loc10=null;
            var loc12=0;
            if (arg1 == null) 
            {
                this._rankTxt.text = "";
                this._nameTxt.text = "";
                this._careerTxt.text = "";
                this._ownerTxt.text = "";
                this._scoreTxt.text = "";
                this._rangeTxt.text = "";
                if (this._bitmap.parent) 
                {
                    removeChild(this._bitmap);
                }
                clearBgColor();
                _data = null;
                return;
            }
            _data = arg1;
            var loc1=_data.rank;
            this._rankTxt.text = loc1.toString();
            var loc2=new ItemData(_data.entityId);
            var loc3=ColorConfig.instance.getItemColorString(loc2.itemInfo.item.color);
            this._nameTxt.htmlText = "<font color=\'" + loc3 + "\'><a href=\'event: 0\'><u>" + loc2.itemInfo.item.name + "</u></a></font>";
            this._nameTxt.addEventListener(flash.events.TextEvent.LINK, this.onNameTxtLinkHandler);
            var loc4=loc2.itemInfo.item.career;
            var loc5=CareerUtil.getEquipCareerArray(loc4);
            var loc6="";
            if (loc5 && loc5.length > 0) 
            {
                loc12 = 0;
                while (loc12 < loc5.length) 
                {
                    loc6 = loc6 + CareerConfig.instance.getInfoByCode(loc5[loc12]).name;
                    if (loc12 != (loc5.length - 1)) 
                    {
                        loc6 = loc6 + " , ";
                    }
                    ++loc12;
                }
            }
            else 
            {
                loc6 = CareerConfig.instance.getInfoByCode(_data.propertyThree).name;
            }
            this._careerTxt.text = loc6;
            var loc7=_data.propertyOne;
            var loc8=ColorConfig.instance.getCountryColor(loc7).intColor;
            this._ownerTxt.text = _data.ownerName;
            this._ownerTxt.setTextFormat(new GTextFormat("", 12, loc8, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._scoreTxt.text = _data.valueOne + "";
            if (this._bitmap.parent) 
            {
                removeChild(this._bitmap);
            }
            var loc9=_data.lastRank;
            var loc11=true;
            if (loc9 != 0) 
            {
                if (loc1 > loc9) 
                {
                    this._bitmap = GlobalClass.getBitmap(ImagesConst.RangeDecline);
                    loc10 = (loc1 - loc9).toString();
                }
                else if (loc1 < loc9) 
                {
                    this._bitmap = GlobalClass.getBitmap(ImagesConst.RangeRaise);
                    loc10 = (loc9 - loc1).toString();
                }
                else if (loc1 == loc9) 
                {
                    this._bitmap = GlobalClass.getBitmap(ImagesConst.RangeSame);
                    loc10 = "";
                }
            }
            else 
            {
                loc11 = false;
                loc10 = Language.getString(32078);
            }
            if (loc11) 
            {
                this._bitmap.x = 418;
                this._bitmap.y = 2;
                addChild(this._bitmap);
            }
            this._rangeTxt.text = loc10.toString();
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (_data == null) 
            {
                return;
            }
            this._isClick = true;
            this._stageX = arg1.stageX;
            this._stageY = arg1.stageY;
            return;
        }

        /* internal  */onNameTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=_data.entityUid;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RankGetEquipTipsInfos, loc1));
            arg1.stopImmediatePropagation();
            return;
        }

        public showToolTips(arg1: int, arg2: string): void
        {
            var loc1=new ItemData(arg1);
            loc1.setItemExInfo(JSON.deserialize(arg2));
            if (!EquipmentRankItem._toolTip) 
            {
                EquipmentRankItem._toolTip = new Tooltip();
                EquipmentRankItem._closeBtn = ObjCreate.createGButton("", EquipmentRankItem._toolTip.width - 24, 4, 20, 18, null, "SmallCLoseBtn");
                EquipmentRankItem._spTooltipContainer.addChild(EquipmentRankItem._toolTip);
                EquipmentRankItem._spTooltipContainer.addChild(EquipmentRankItem._closeBtn);
            }
            EquipmentRankItem._toolTip.data = loc1.getToolTipData();
            EquipmentRankItem._spTooltipContainer.x = this._stageX;
            EquipmentRankItem._spTooltipContainer.y = this._stageY;
            LayerManager.toolTipLayer.addChild(EquipmentRankItem._spTooltipContainer);
            EquipmentRankItem._closeBtn.x = EquipmentRankItem._toolTip.width - 24;
            EquipmentRankItem._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.closeTootipHandler);
            this.resetToolTipPosition();
            return;
        }

        public closeTootipHandler(arg1: Object /* flash.events.MouseEvent */=null): void
        {
            if (EquipmentRankItem._spTooltipContainer && EquipmentRankItem._spTooltipContainer.parent) 
            {
                EquipmentRankItem._spTooltipContainer.parent.removeChild(EquipmentRankItem._spTooltipContainer);
            }
            return;
        }

        /* internal  */resetToolTipPosition(): void
        {
            if (EquipmentRankItem._spTooltipContainer.x > Global.stage.stageWidth - EquipmentRankItem._spTooltipContainer.width - 6) 
            {
                EquipmentRankItem._spTooltipContainer.x = EquipmentRankItem._spTooltipContainer.x - EquipmentRankItem._spTooltipContainer.width - 6;
            }
            var loc1=1;
            if (EquipmentRankItem._spTooltipContainer.y + EquipmentRankItem._spTooltipContainer.height > Global.stage.stageHeight) 
            {
                EquipmentRankItem._spTooltipContainer.y = Global.stage.stageHeight - EquipmentRankItem._spTooltipContainer.height;
            }
            if (EquipmentRankItem._spTooltipContainer.y < 0) 
            {
                EquipmentRankItem._spTooltipContainer.y = 0;
            }
            return;
        }

        protected /* var */_tf: Object /* flash.text.TextFormat */;

        protected /* var */_rankTxt: Object /* flash.text.TextField */;

        protected /* var */_nameTxt: Object /* flash.text.TextField */;

        protected /* var */_careerTxt: Object /* flash.text.TextField */;

        protected /* var */_ownerTxt: Object /* flash.text.TextField */;

        protected /* var */_scoreTxt: Object /* flash.text.TextField */;

        protected /* var */_rangeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_bitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_isClick: Boolean=false;

        /* internal */ /* var */_stageX: number;

        /* internal */ /* var */_stageY: number;

        /* internal */ static /* var */_toolTip: Tooltip;

        /* internal */ static /* var */_closeBtn: GButton;

        /* internal */ static /* var */_spTooltipContainer: Object /* flash.display.Sprite */;
    }

            EquipmentRankItem._spTooltipContainer = new Object /* flash.display.Sprite */();
        